<?php

class RouteModel {

	private $startDate;
	private $places; // array
	private $startPlace;
	private $endPlace;
	private $totalDist;
	private $name;
	private $routeNumber;
	private $routeType;

	public function __construct($start, $stop, $date){
		$this->startDate = $date;
		$this->startPlace = $start;
		$this->endPlace = $stop;
	}

	public function getStartDate(){ return $this->startDate; }
	public function getPlaceArray(){ return $this->places; }
	public function getPlace($pos){ return $this->places[$pos]; }
	public function getStartPlace(){ return $this->startPlace; }
	public function getEndPlace() { return $this->endPlace; }
	public function getName() { return $this->name; }
	public function getRouteNumber() { return $this->routeNumber; }
	public function getRouteType() { return $this->routeType; }
	
	public function getStartHour(){
		$fromdate = explode('T',$this->startDate);
		$fromTime = explode(':',$fromdate[1]);
		return $fromTime[0];
	}
	
	public function setName($param){ $this->name = $param; }
	public function setRouteNumber($param){ $this->routeNumber = $param; }
	public function setRouteType($param){ $this->routeType = $param; }
	public function setStartDate($param){ $this->startDate = $param; }
	public function setAllPlaces($param){ $this->places = $param; }
	public function setStartPlace($param){ $this->startPlace = $param; }
	public function setEndPlace($param){ $this->endPlace = $param; }
	 
	public function addPlace($place, $dist=null, $date=0, $generateNow=false ){
		$this->places[] = $place;
		$place->setDistance($dist);
		if (!is_null($dist)){
			$place->generateDate($date, $dist);
		}else{
			$place->setFromDate($date);
		}
		 
		if ($generateNow){
			$this->generateForecast();
		}
	}

	public function setReversedOrder(){
		$this->places = array_reverse($this->places);
		 
	}

	public function generateForecast(){
		//$query = '/weatherdata/product/time[@from="'.$place->getFromDate().'"]/location';
		foreach($this->places as $place){
			$result = forecastDao::getWeather($place->getLatitude(),$place->getLongitude());
			$place->setForcastDays($result);
		}
	}

	public function setTotalDist($dist){
		$this->totalDist = $dist;
	}

	public function getTotalDist(){ return $this->totalDist; }
}
?>